<template>
  <div class="visitor-alreadyVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">人员类型:</div>
        <div class="input-item">
          <a-select
            v-model="queryParam.helpPersonType"
            ref="select"
            show-search
            placeholder="请选择"
            class="select-jurisdiction"
          >
            <a-select-option :value="item.value" v-for="(item, index) in helpTypeList" :key="index">{{
              item.text
            }}</a-select-option>
          </a-select>
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">人员姓名:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model="queryParam.helpPersonName" placeholder="请输入" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">身份证号:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model="queryParam.helpPersonIdCard" placeholder="请输入" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">手机号码:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model="queryParam.helpPersonIdPhone" placeholder="请输入" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">创建时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>
      <div class="btn-wrap">
        <a-button class="searchBtn" @click="searchQuery()" type="primary"> 搜索 </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>
    <div>
      <a-table
        ref="table"
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
        :scroll="{ x: 1000 }"
      >
        <template slot="action" slot-scope="records">
          <span class="operation deatil-color" @click="handleDetail(records)">详情</span>
          <span class="operation deatil-color" v-if="true" @click="handleEdit(records)">编辑</span>
          <span class="operation" style="color: #ff5e5e" @click="handleDelete(records)">删除</span>
        </template>
      </a-table>
    </div>
    <!-- <Detail type="repair" ref="rentDetailRef" /> -->
    <BindingPersonnel ref="bindingPersonnelRef" />
    <Detail ref="detailRef" />
    <allMessage
      ref="allMessage"
      :publicVisible="publicVisible"
      @cancel="publicVisible = false"
      @tipMessage="tipMessage"
    ></allMessage>
    <Add ref="addRef" @refresh="onRefresh" />
  </div>
</template>

<script>
import startEndTime from '@/components/startEndTime'
import { JeecgListMixinNew } from '@/mixins/JeecgListMixinNew'
import { getCommunityList, getDictItemsFromCache, getSubordinateList } from '@/api/api'
import Detail from './detail.vue'
import { handleSelectChange } from '../../../../utils/util'
import moment from 'moment'
import allMessage from '@/components/allMessage'
import BindingPersonnel from './bindingPersonnel'
import { deleteAction, postAction } from '@/api/manage'
import Add from './add.vue'

export default {
  name: 'room',
  components: { startEndTime, BindingPersonnel, Detail, allMessage, Add },
  mixins: [JeecgListMixinNew],
  props: {
    idCode: {
      type: String,
      default: '',
    },
    villageList: {
      type: Array,
      default: () => [],
    },
  },
  watch: {
    idCode(newVal) {
      this.extendParams.policeAgencyId = newVal
    },
  },
  data() {
    return {
      url: {
        list: '/wb/helpinfo/page',
      },
      publicVisible: false,
      disableMixinCreated: false,
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 60,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
          fixed: 'left',
        },
        {
          title: '人员类型',
          dataIndex: 'helpPersonTypeText',
          ellipsis: true,
          align: 'center',
          width: 160,
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '人员姓名',
          dataIndex: 'helpName',
          ellipsis: true,
          align: 'center',
          width: 160,
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '身份证号',
          dataIndex: 'helpIdCard',
          ellipsis: true,
          align: 'center',
          width: 160,
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '电话号码',
          dataIndex: 'helpPhone',
          ellipsis: true,
          align: 'center',
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
          width: 160,
        },
        {
          title: '备注信息',
          dataIndex: 'orgName',
          ellipsis: true,
          align: 'center',
          width: 160,
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },

        {
          title: '创建时间',
          dataIndex: 'createTime',
          ellipsis: true,
          align: 'center',
          width: 180,
          customRender: (t) => {
            return (
              <a-tooltip placement="top">
                <template slot="title">
                  <span>{t}</span>
                </template>
                <div class="ant-table-row-cell-ellipsis">{t}</div>
              </a-tooltip>
            )
          },
        },
        {
          title: '更新时间',
          dataIndex: 'updateTime',
          ellipsis: true,
          align: 'center',
          width: 180,
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          ellipsis: true,
          align: 'center',
          width: 200,
          fixed: 'right',
        },
      ],
      project_company_type: [],
      times: {},
      buildingList: [],
      unitList: [],
      floorList: [],
      roomList: [],
      queryParam: {
        companyName: undefined,
        reasonForReporting: undefined,
        printName: undefined,
        mobile: undefined,
      },
      flagTypeList: [],
      extendParams: {},
      reasonForReporting: [],
      bindingPersonnelRef: null,
      detailRef: null,
      helpTypeList: getDictItemsFromCache('wb_help_type'),
      addRef: null,
    }
  },
  mounted() {
    this.flagTypeList = getDictItemsFromCache('flag_type')
    this.reasonForReporting = getDictItemsFromCache('reason_for_reporting')
    this.initPage()
  },
  methods: {
    handleDetail(records) {
      this.$refs.detailRef.show(records)
    },
    handleEdit(records) {
      this.$refs.detailRef.show(records, 'edit')
    },
    searchReset() {
      if (this.resetTime !== undefined) {
        this.resetTime = true
      }
      this.queryParam = {}
      this.loadData(1)
    },
    handleSelectChange,
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    searchQuery() {
      this.loadData(1)
    },
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.startTime = this.$moment(v).valueOf()
      } else {
        this.queryParam.endTime = this.$moment(v).valueOf()
      }
      if (v == null) {
        this.queryParam.startTime = null
        this.queryParam.endTime = null
      }
    },
    async initPage() {
      try {
        console.log(res)
      } catch (error) {
      } finally {
      }
    },
    handleBindPatient(records) {
      this.$refs.bindingPersonnelRef.show(records)
    },
    handleDelete(records) {
      this.confirmTitle = '删除'
      this.publicVisible = true
      this.$refs.allMessage.show(records)
    },
    async tipMessage(records) {
      let res
      if (this.confirmTitle === '删除') {
        res = await postAction('/wb/helpinfo/deleteHelpInfo', { id: records.id })
      }
      this.$message.success(res.message)
      this.publicVisible = false
      this.searchQuery()
    },
    onRefresh() {
      this.loadData()
    },
    handleEdit(records) {
      this.$refs.addRef.show(records, 'edit')
    },
  },
}
</script>
